package com.example.demo.controller;


import com.example.config.ErrorCodeEnum;
import com.example.controller.BaseController;
import com.example.demo.entity.UserT;
import com.example.demo.service.impl.UserTServiceImpl;
import com.power.common.model.CommonResult;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hangge
 * @since 2020-07-25
 */
@RestController
@Controller
@RequestMapping("/userT")
public class UserTController extends BaseController {

     private static Logger logger =  LoggerFactory.getLogger(UserTController.class);
     @Autowired
     private UserTServiceImpl userTServiceImpl;

     @RequestMapping(value = "/getUserTInfo",method = {RequestMethod.GET})
     public void getUserTInfo(Integer id, HttpServletResponse response){
         try {
             UserT userT = userTServiceImpl.selectByid(id);
             if (userT == null){
                 userT = new UserT();
             }
             this.writeJson(CommonResult.ok(ErrorCodeEnum.Select_SUCCESS).setResult(userT),response);
         } catch (Exception e) {
             e.printStackTrace();
             this.writeJson(CommonResult.fail(ErrorCodeEnum.Select_Fail),response);
         }
     }
     
     @RequestMapping(value = "/getUserListById",method = {RequestMethod.GET})
     public void getUserListById(Integer id,HttpServletResponse response){
         try {
             List<UserT> list =userTServiceImpl.selectList(id);
             logger.info(list.toString());
             this.writeJson(CommonResult.ok(ErrorCodeEnum.Select_SUCCESS).setResult(list),response);
         } catch (Exception e) {
             e.printStackTrace();
             this.writeJson(CommonResult.fail(ErrorCodeEnum.Select_Fail),response);
         }
     }

    @RequestMapping(value = "/getUserListByMobile",method = {RequestMethod.GET})
    public void getUserListByMobile(String mobile,HttpServletResponse response){
        try {
            List<UserT> list =userTServiceImpl.selectListByMobile(mobile);
            logger.info(list.toString());
            this.writeJson(CommonResult.ok(ErrorCodeEnum.Select_SUCCESS).setResult(list),response);
        } catch (Exception e) {
            e.printStackTrace();
            this.writeJson(CommonResult.fail(ErrorCodeEnum.Select_Fail),response);
        }
    }
}

